#ifndef MULTICASTER_H
#define MULTICASTER_H

#include <string>
#include <utility>

#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>

#include "model/dom.h"

#include "core/null_deleter.h"

#include "thread_helper.h"
#include "worker_thread.h"
#include "event_handler.h"
#include "listener.h"
#include "notifier.h"
#include "network.h"

using namespace std;

namespace network {
	class multicaster : public network::worker_thread, 
			    public network::listener {
	public:
		typedef boost::shared_ptr<network::event_handler> 
			event_ptr;

		multicaster(boost::shared_ptr<network::message_queue> q,
			    boost::shared_ptr<network::event_queue> e)
		: _message_q(q), _event_q(e) {}
		virtual ~multicaster() {}

		virtual void run();

		void add_handler(boost::shared_ptr<network::event_handler> h);
		void remove_handler(
			boost::shared_ptr<network::event_handler> h);

		virtual void notify(const network::notifier *n);
	private:
		list<event_ptr> _events;
		boost::mutex _monitor;

		boost::shared_ptr<network::message_queue> _message_q;
		boost::shared_ptr<network::event_queue> _event_q;
	};
}

#endif
